﻿package mvc_model
{
	import flash.events.Event;
	import mvc_model.Model;

	// Model class used to hold nerds/user data
	public class NerdsPageModel extends Model
	{
		private var _userList:XMLList;
		private var _numUsers:int;
		
		public function NerdsPageModel()
		{
			_numUsers = 0;
		}
		
		public function get numUsers():int
		{
			return _numUsers;
		}
		
		// if index out of range return null
		public function getUsername(index:int):String
		{
			if (index >= _numUsers) return "";
			return _userList[index].username;
		}
		
		public function getFirstName(index:int):String
		{
			if (index >= _numUsers) return "";
			return _userList[index].first_name;
		}
		
		public function getLastName(index:int):String
		{
			if (index >= _numUsers) return "";
			return _userList[index].last_name;
		}
		
		public function getDataOfBirth(index:int):String
		{
			if (index >= _numUsers) return "";
			return _userList[index].date_of_birth;
		}
		
		public function getAvatar(index:int):String
		{
			if (index >= _numUsers) return null;
			return _userList[index].picture;
		}
		
		public function dateOfCreation(index:int):String
		{
			if (index >= _numUsers) return null;
			return _userList[index].date_of_creation;
		}
		
		// protected method may not be needed
		override protected function updateData():void
		{
			
		}
		
		// set the userList to be used by the view
		override protected function dataLoaded(event:Event):void
		{
			data = new XML(loader.data);
			_userList = data.user;
			_numUsers = _userList.length();
			setCurrentIndex(0);
		}
	}
}